package singleton;

//枚举
public class CreatSingleton3 {
    private static CreatSingleton3 singleton;
    private CreatSingleton3(){
        System.out.println(Thread.currentThread().getName()+"正在调用构造方法");
    }
    public static CreatSingleton3 getSingleton() {
        return Demo.INSTANCE.singleton;
    }
    //定义一个枚举，获取CreatSingleton3的实例
    public enum  Demo{
        INSTANCE;
        private CreatSingleton3 singleton;
        private Demo() {
            System.out.println("Demo的构造函数..");
            singleton = new CreatSingleton3();
        }

        public  CreatSingleton3 getSingleton() {
            return singleton;
        }
    }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                CreatSingleton3.getSingleton();
            },String.valueOf(i)).start();

        }
    }
}
